package localization;
import java.util.Hashtable;

public class LocalizationManager {
	
	private static Language DEFAULT_LANGUAGE = new PolishLanguage();
	
	private Hashtable localesToLanguageTable = new Hashtable(3);
	
	private Language currentLanguage;
	
	private static LocalizationManager instance;
	
	private LocalizationManager() {
		fillLocalesTable();
		setCurrentLanguage( getSystemLocaleLanguage() );
	}
	
	private void fillLocalesTable(){
		localesToLanguageTable.put("pl_PL", new PolishLanguage() );
	}
	
	private Language getLanguageFromLocale( String locale ) {
		Language language = (Language) localesToLanguageTable.get( locale ); 
		
		if(language != null) {
			return language; 
		} else {
			return DEFAULT_LANGUAGE;
		}
	}
	
	public Language getSystemLocaleLanguage(){
		String locale = System.getProperty("microedition.locale");
		return getLanguageFromLocale(locale);		
	}

	public Language getCurrentLanguage() {
		return currentLanguage;
	}

	public void setCurrentLanguage(Language currentLanguage) {
		this.currentLanguage = currentLanguage;
	}

	public static LocalizationManager getInstance() {
		if( instance == null ) {
			instance = new LocalizationManager();
		}
		
		return instance;
	}	
	
	public static Language getCurrentLanguageFromInstance(){
		return getInstance().getCurrentLanguage();		
	}
	
}
